package com.blb.demo3;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池案例
 * 单例线程池
 */
public class ExecutorDemo3 {

    public static void testNewCachedThreadPool() {
        //创建单例线程池
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 10000; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + "执行了");
                }
            });
        }
        executorService.shutdown();
    }

    public static void main(String[] args) {
        testNewCachedThreadPool();
    }

}
